package com.monboo.album.view.component
{
	import com.monboo.album.common.AlbumConst;
	import com.monboo.utils.FullState;
	import com.monboo.album.view.AlbumInfoMediator;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.filters.BitmapFilter;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class AlbumText extends Sprite
	{
		private var textArr:Array = new Array();
		private var textObj:Object;
		public var text:TextField = new TextField();
		
		private var filter:BitmapFilter;
		private var filterArr:Array = new Array();
		
		private var fullFormat:TextFormat = new TextFormat();
		private var noFullFormat:TextFormat = new TextFormat();
		private var _stage:Stage;
		
		private var imageInfo:AlbumInfoMediator;
		
		public function AlbumText(_textArr:Array,_textObj:Object,_imageInfo:AlbumInfoMediator){
			
			textArr = _textArr;
			textObj = _textObj;
			imageInfo = _imageInfo;

			addEventListener(Event.ADDED_TO_STAGE,addToStageFunc);
			
		}
		private function addToStageFunc(e:Event):void{
			_stage = parent.stage;
			initText();
		}
		private function initText():void{
			text.width = imageInfo.imageWidth;
			text.selectable = false;
			
			filter = getBitmapFilter();
			filterArr.push(filter);
			text.filters = filterArr;
			
			if(textObj && textObj.fontSize){noFullFormat.size = textObj.fontSize;}else{noFullFormat.size=14;}
			noFullFormat.align = "center";
			if(textObj && textObj.fontColor){noFullFormat.color = textObj.fontColor;}else{noFullFormat.color=0xffffff;}
			text.defaultTextFormat = noFullFormat;
			
			addChild(text);
			
			doText(0);
		}
		
		public function textFormat():void{
		
			if(FullState.fullState){
				text.width = _stage.stageWidth;
				if(textObj && textObj.fontSize){fullFormat.size = int(textObj.fontSize)+15;}else{noFullFormat.size=30;}
				fullFormat.align = "center";
				if(textObj && textObj.fontColor){fullFormat.color = textObj.fontColor;}else{noFullFormat.color=0xffffff;}
				text.setTextFormat(fullFormat);
				
				x = 0;
				y = _stage.stageHeight - text.textHeight - 42;
			}else{				
				text.width = imageInfo.imageWidth;
				if(textObj && textObj.fontSize){noFullFormat.size = textObj.fontSize;}else{noFullFormat.size=14;}
				noFullFormat.align = "center";
				if(textObj && textObj.fontColor){noFullFormat.color = textObj.fontColor;}else{noFullFormat.color=0xffffff;}
				text.setTextFormat(noFullFormat);
				
				x = imageInfo.albumTextX;
				y = imageInfo.albumTextY - text.textHeight - 6;
			}
			
		}
		
		public function getTextField():TextField{
			return text;
		}
		public function doText(n:int):void{
			
			text.htmlText = "";
			text.htmlText  = String(textArr[n]);
			
			textFormat();
		}
		public function getText(n:int):String{
			return String(textArr[n]);
		}
		
		private function getBitmapFilter():BitmapFilter{
			var color:Number;
			if(textObj && textObj.fontBg){color=textObj.fontBg;}else{color=0x000000;}
			var alpha:Number=0.8;
			var blurX:Number=10;
			var blurY:Number=10;
			var strength:Number=2;
			var inner:Boolean=false;
			var knockout:Boolean=false;
			var quality:Number=BitmapFilterQuality.HIGH;
			return new GlowFilter(color,alpha,blurX,blurY,strength,quality,inner,knockout);
			
		}
				
	}
}